package com.sixth.service.impl;

import com.sixth.dao.PayLogDao;
import com.sixth.service.OrderService;
import com.sixth.until.CommonResult;
import com.sixth.vo.DateVo;
import com.sixth.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: 厉泽禄
 * @create: 2022-04-21 17:05
 **/
@Service(value = "orderService")
public class OrderServiceImpl implements OrderService {
    @Autowired
    private PayLogDao payLogDao;

    @Override
    public CommonResult queryAllOrderBang(DateVo dateVo) {
        String s1 = dateVo.getGmtCreate() + "";
        String s2 = dateVo.getGmtModified() + "";
        String startYear = s1.substring(s1.length() - 4, s1.length());
        String stopYear = s2.substring(s2.length() - 4, s2.length());
        List<String> times = payLogDao.findOrder();
        ArrayList<OrderVo> orderVos = new ArrayList<>();
        HashSet<String> years = new HashSet<>();
        for (String s : times) {
            String year = s.substring(0, 4);
            years.add(year);
        }
        Iterator iterator = years.iterator();
        while (iterator.hasNext()) {
            String next = (String) iterator.next();
            int i = Integer.parseInt(next);
            if ("null".equals(startYear) && "null".equals(stopYear)) {
                String money = payLogDao.findMoney(next);
                OrderVo orderVo = new OrderVo(next, money);
                orderVos.add(orderVo);
            } else {
                int i1 = Integer.parseInt(startYear);
                int i2 = Integer.parseInt(stopYear);
                if (i >= i1 && i <= i2) {
                    String money = payLogDao.findMoney(next);
                    OrderVo orderVo = new OrderVo(next, money);
                    orderVos.add(orderVo);
                }
            }
        }
        return new CommonResult(2000, "查询成功", orderVos);
    }
}
